using System.Drawing;
using System.Windows.Forms;

namespace OpenComposite.Base.Designer
{
	public class ToolBoxRenderer : ToolStripProfessionalRenderer
	{
		protected override void OnRenderItemImage(ToolStripItemImageRenderEventArgs e)
		{
			Rectangle r = new Rectangle(e.ImageRectangle.Location, new Size(16, 16));
			e = new ToolStripItemImageRenderEventArgs(e.Graphics, e.Item, e.Image, r);
			base.OnRenderItemImage(e);
		}
		protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
		{
			e.TextFormat |= TextFormatFlags.EndEllipsis;
			if ( e.TextRectangle.X < 18 )
				e.TextRectangle = new Rectangle(18, e.TextRectangle.Y, e.TextRectangle.Width + e.TextRectangle.X - 18, e.TextRectangle.Height);
			base.OnRenderItemText(e);
		}
		protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
		{
			//base.OnRenderToolStripBorder(e);
		}
		protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
		{
			base.OnRenderToolStripBackground(e);
			using ( SolidBrush b = new SolidBrush(e.BackColor) ) {
				e.Graphics.FillRectangle(b, e.AffectedBounds);
			}
		}
		protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
		{
			//base.OnRenderSeparator(e);
			if ( e.Vertical )
				e.Graphics.DrawLine(SystemPens.ControlDarkDark,
					e.Item.ContentRectangle.Left, e.Item.ContentRectangle.Top,
					e.Item.ContentRectangle.Left, e.Item.ContentRectangle.Bottom);
			else
				e.Graphics.DrawLine(SystemPens.ControlDarkDark,
					e.Item.ContentRectangle.Left, e.Item.ContentRectangle.Top,
					e.Item.ContentRectangle.Right, e.Item.ContentRectangle.Top);
		}
	}
}
